
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>SpringBoot自动装载机制 - 源码分析 · JAVA学习积累</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tianwyam">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="spring_feign.html" />
    
    
    <link rel="prev" href="spring/spring_interview_questions_68.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blog.csdn.net/mybook201314" target="_blank" class="custom-link">博客Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">【前言】</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍ABOUT
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第一章】Java基础</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java/java.html">
            
                <a href="../java/java.html">
            
                    
                    计算机基础-操作系统-进程-计算机网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java/java_thread_pool.html">
            
                <a href="../java/java_thread_pool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java/java_ftp.html">
            
                <a href="../java/java_ftp.html">
            
                    
                    FTP文件服务器上传下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java/collection.html">
            
                <a href="../java/collection.html">
            
                    
                    集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../java/collection/java_collection_map.html">
            
                <a href="../java/collection/java_collection_map.html">
            
                    
                    Map&HashMap&HashTable&ConcurrentHashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../java/java_queue.html">
            
                <a href="../java/java_queue.html">
            
                    
                    队列-queue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../java/java_tree.html">
            
                <a href="../java/java_tree.html">
            
                    
                    二叉树遍历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java/java_io_nio.html">
            
                <a href="../java/java_io_nio.html">
            
                    
                    java输入输出流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java/java_exception.html">
            
                <a href="../java/java_exception.html">
            
                    
                    异常exception
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java/java_serialize.html">
            
                <a href="../java/java_serialize.html">
            
                    
                    Java序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java/Java_annotation.html">
            
                <a href="../java/Java_annotation.html">
            
                    
                    注解
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../java/multi.html">
            
                <a href="../java/multi.html">
            
                    
                    多线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                <a href="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                    
                    volatile&synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                <a href="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                    
                    object/wait/notify
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../java/multithread/java_multi_thread_thread.html">
            
                <a href="../java/multithread/java_multi_thread_thread.html">
            
                    
                    thread
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../java/multithread/java_multi_thread_threadpool.html">
            
                <a href="../java/multithread/java_multi_thread_threadpool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../java/multithread/java_multi_thread_lock.html">
            
                <a href="../java/multithread/java_multi_thread_lock.html">
            
                    
                    lock&ReentrantLock&ReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../java/multithread/java_multi_thread_lock_condition.html">
            
                <a href="../java/multithread/java_multi_thread_lock_condition.html">
            
                    
                    lock&condition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../java/multithread/java_multi_thread_tools.html">
            
                <a href="../java/multithread/java_multi_thread_tools.html">
            
                    
                    Java并发工具- CountDownLatch&CyclicBarrier 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../java/multithread/java_multi_thread_tools2.html">
            
                <a href="../java/multithread/java_multi_thread_tools2.html">
            
                    
                    Java同步工具类- CountDownLatch&CyclicBarrier&Semaphore  
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java/java_jvm.html">
            
                <a href="../java/java_jvm.html">
            
                    
                    java虚拟机-JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../java/java_java7new.html">
            
                <a href="../java/java_java7new.html">
            
                    
                    java7新知识- Switch&TWR&Objects 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../java/java_stream.html">
            
                <a href="../java/java_stream.html">
            
                    
                    Java8对集合流操作stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../java/java_stream_groupby.html">
            
                <a href="../java/java_stream_groupby.html">
            
                    
                    java8新语法-Stream-分组groupingBy操作 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../java/java_optional.html">
            
                <a href="../java/java_optional.html">
            
                    
                    java8新语法-Optional 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../java/java_8new_date_api.html">
            
                <a href="../java/java_8new_date_api.html">
            
                    
                    java8-新的日期时间API 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../xml/xml_translation.html">
            
                <a href="../xml/xml_translation.html">
            
                    
                    XML中特殊符号的转译 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../datastructure/binary_complement.html">
            
                <a href="../datastructure/binary_complement.html">
            
                    
                    原码、反码、补码 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../java/basic/javabean2map.html">
            
                <a href="../java/basic/javabean2map.html">
            
                    
                    Java bean转Map 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第二章】算法积累题</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../algorithm/merge_sorted_array.html">
            
                <a href="../algorithm/merge_sorted_array.html">
            
                    
                    算法题 - 合并排序数组 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../algorithm/lowest_score.html">
            
                <a href="../algorithm/lowest_score.html">
            
                    
                    算法题 - 最低分数线问题 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../algorithm/array_sub_list.html">
            
                <a href="../algorithm/array_sub_list.html">
            
                    
                    算法题 - 求数组的子集合 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第三章】框架</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="springboot.html">
            
                <a href="springboot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="spring_security.html">
            
                <a href="spring_security.html">
            
                    
                    SpringSecurity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../linux/linux_commands_springboot_startup.html">
            
                <a href="../linux/linux_commands_springboot_startup.html">
            
                    
                    SpringBoot项目启动脚本
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="10.1" data-path="spring/spring_interview_questions_68.html">
            
                <a href="spring/spring_interview_questions_68.html">
            
                    
                    Spring面试题68
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter active" data-level="11.1" data-path="springboot_auto_config.html">
            
                <a href="springboot_auto_config.html">
            
                    
                    SpringBoot自动装载机制 - 源码分析
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="spring_feign.html">
            
                <a href="spring_feign.html">
            
                    
                    Feign在spring、springboot下使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="13.1" data-path="spring_freemarker.html">
            
                <a href="spring_freemarker.html">
            
                    
                    Spring boot集成freemarker，生成word文件
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="14.1" data-path="spring_freemarker_generate.html">
            
                <a href="spring_freemarker_generate.html">
            
                    
                    Freemarker自动生成Java bean代码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="15.1" data-path="../mybatis/mybatis_metadata.html">
            
                <a href="../mybatis/mybatis_metadata.html">
            
                    
                    mybatis中操作元数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.2" data-path="../mybatis/mybatis_batch_exec_sql.html">
            
                <a href="../mybatis/mybatis_batch_exec_sql.html">
            
                    
                    mybatis中insert/update/delete标签中执行多条SQL语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.3" data-path="../mybatis/mybatis_plus.html">
            
                <a href="../mybatis/mybatis_plus.html">
            
                    
                    springboot集成mybatis-plus框架
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="16.1" data-path="../distributed/sharding-jdbc.html">
            
                <a href="../distributed/sharding-jdbc.html">
            
                    
                    【分布式】sharding-jdbc实现分库分表
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第四章】数据库</li>
        
        
    
        <li class="chapter " data-level="17.1" data-path="../SQL/sql.html">
            
                <a href="../SQL/sql.html">
            
                    
                    SQL常用使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="18.1" data-path="../redis/redis_study_notes.html">
            
                <a href="../redis/redis_study_notes.html">
            
                    
                    redis学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="18.2" data-path="../redis/redis_list_second_kill.html">
            
                <a href="../redis/redis_list_second_kill.html">
            
                    
                    Redis中的队列list实现秒杀活动抢购
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="19.1" data-path="../SQL/sql_mysql_green_install.html">
            
                <a href="../SQL/sql_mysql_green_install.html">
            
                    
                    mysql绿色版安装服务教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.2" data-path="../SQL/sql_h2.html">
            
                <a href="../SQL/sql_h2.html">
            
                    
                    H2内嵌数据的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.3" data-path="../SQL/cache.html">
            
                <a href="../SQL/cache.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.4" data-path="../SQL/mysql/mysql_back_rollback.html">
            
                <a href="../SQL/mysql/mysql_back_rollback.html">
            
                    
                    MySQL单表备份还原
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第五章】Web</li>
        
        
    
        <li class="chapter " data-level="20.1" data-path="../web/web_js_jquery.html">
            
                <a href="../web/web_js_jquery.html">
            
                    
                    web简单积累
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第六章】Linux</li>
        
        
    
        <li class="chapter " data-level="21.1" data-path="../linux/linux_common_commands.html">
            
                <a href="../linux/linux_common_commands.html">
            
                    
                    linux常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第七章】Windows</li>
        
        
    
        <li class="chapter " data-level="22.1" data-path="../windows/windows_common_commands.html">
            
                <a href="../windows/windows_common_commands.html">
            
                    
                    windows常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第八章】错误集</li>
        
        
    
        <li class="chapter " data-level="23.1" data-path="../error/maven_not_found_local_jar.html">
            
                <a href="../error/maven_not_found_local_jar.html">
            
                    
                    maven引入依赖时识别不到本地仓库的jar
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="24.1" data-path="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                <a href="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                    
                    spring security 配置发生错误 Can't configure antMatchers after anyRequest
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="25.1" data-path="../error/AOP_stream_close_error.html">
            
                <a href="../error/AOP_stream_close_error.html">
            
                    
                    AOP内获取了对请求流操作后报流已经关闭错误的问题
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="26.1" data-path="../tools/github/github_ssh.html">
            
                <a href="../tools/github/github_ssh.html">
            
                    
                    Github ssh key 解决提交后push频繁输入用户名和密码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="27.1" data-path="../error/sharding-jdbc-error-datasources.html">
            
                <a href="../error/sharding-jdbc-error-datasources.html">
            
                    
                    sharding-jdbc-4.1.1版本启动数据源报错问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >SpringBoot自动装载机制 - 源码分析</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#spring-boot-&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;"><b></b>Spring boot &#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;</a></li><ul><li><span class="title-icon "></span><a href="#&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x5B9E;&#x73B0;"><b></b>&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x5B9E;&#x73B0;</a></li><ul><li><span class="title-icon "></span><a href="#&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;"><b></b>&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;"><b></b>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#&#x5B9A;&#x4E49;importselector&#x7684;&#x5B9E;&#x73B0;&#x7C7B;"><b></b>&#x5B9A;&#x4E49;ImportSelector&#x7684;&#x5B9E;&#x73B0;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#&#x5B9A;&#x4E49;&#x914D;&#x7F6E;&#x6CE8;&#x89E3;"><b></b>&#x5B9A;&#x4E49;&#x914D;&#x7F6E;&#x6CE8;&#x89E3;</a></li><li><span class="title-icon "></span><a href="#&#x4E3B;&#x7C7B;"><b></b>&#x4E3B;&#x7C7B;</a></li></ul><li><span class="title-icon "></span><a href="#enableautoconfiguration"><b></b>@EnableAutoConfiguration</a></li><li><span class="title-icon "></span><a href="#autoconfigurationimportselector"><b></b>AutoConfigurationImportSelector</a></li><li><span class="title-icon "></span><a href="#import"><b></b>@Import</a></li></ul></ul></div><h1 id="spring-boot-&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;"><a name="spring-boot-&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;" class="anchor-navigation-ex-anchor" href="#spring-boot-&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>Spring boot &#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;</h1>
<p>&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x673A;&#x5236;&#x7684;&#x539F;&#x7406;&#xFF1A;</p>
<p>&#x5F53;&#x5728;@Configuration&#x4FEE;&#x9970;&#x7684;&#x7C7B;&#x4E0A;&#x4F7F;&#x7528;<strong>@Import</strong>&#x6CE8;&#x89E3;&#xFF0C;<strong>@Import</strong>&#x5F15;&#x5165;&#x4E86;&#x4E00;&#x4E2A;&#x5B9E;&#x73B0;&#x4E86;<strong>ImportSelector</strong>&#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x6B64;&#x7C7B;&#x4F1A;&#x6267;&#x884C;<strong>selectImports</strong>&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4E9B;&#x914D;&#x7F6E;&#x7C7B;&#xFF0C;spring boot&#x4F1A;&#x628A;&#x8FD9;&#x4E9B;&#x914D;&#x7F6E;&#x7C7B;&#x52A0;&#x8F7D;&#x5230;&#x5BB9;&#x5668;&#x4E2D;&#x5E76;&#x521D;&#x59CB;&#x5316;&#x6B64;&#x7C7B;&#x91CC;&#x9762;&#x7684;&#x914D;&#x7F6E;&#xFF0C;&#x6BD4;&#x5982;&#x5B9A;&#x4E49;&#x7684;&#x4E00;&#x4E9B;&#x7C7B;@Bean&#x6CE8;&#x89E3;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x5BF9;&#x8C61;&#x5E76;&#x6DFB;&#x52A0;&#x5230;bean&#x5BB9;&#x5668;&#x4E2D;</p>
<h2 id="&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x5B9E;&#x73B0;"><a name="&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x5B9E;&#x73B0;" class="anchor-navigation-ex-anchor" href="#&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x5B9E;&#x73B0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x81EA;&#x52A8;&#x88C5;&#x8F7D;&#x5B9E;&#x73B0;</h2>
<p>&#x73AF;&#x5883;&#x51C6;&#x5907;</p>
<p>&#x7248;&#x672C;&#x662F; 2.2.4.RELEASE</p>
<p>maven pom.xml</p>
<pre><code class="lang-xml">
<span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.2.4.RELEASE<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>


<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>fastjson<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.73<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

 <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>
</code></pre>
<h3 id="&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;"><a name="&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;</h3>
<pre><code class="lang-java"><span class="hljs-meta">@Data</span>
<span class="hljs-meta">@Builder</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserBean</span> </span>{

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> userId ;

    <span class="hljs-keyword">private</span> String name ;
}
</code></pre>
<h3 id="&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;"><a name="&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserBeanAutoConfig</span> </span>{


    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> UserBean <span class="hljs-title">userBean</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> UserBean.builder()
                .userId(<span class="hljs-number">12000l</span>)
                .name(<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>)
                .build();
    }

}
</code></pre>
<h3 id="&#x5B9A;&#x4E49;importselector&#x7684;&#x5B9E;&#x73B0;&#x7C7B;"><a name="&#x5B9A;&#x4E49;importselector&#x7684;&#x5B9E;&#x73B0;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x5B9A;&#x4E49;importselector&#x7684;&#x5B9E;&#x73B0;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9A;&#x4E49;ImportSelector&#x7684;&#x5B9E;&#x73B0;&#x7C7B;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserBeanConfigImportSelector</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ImportSelector</span></span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> String[] selectImports(AnnotationMetadata importingClassMetadata) {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> String[] {<span class="hljs-string">&quot;com.tianya.learn.config.UserBeanAutoConfig&quot;</span>};
    }

}
</code></pre>
<h3 id="&#x5B9A;&#x4E49;&#x914D;&#x7F6E;&#x6CE8;&#x89E3;"><a name="&#x5B9A;&#x4E49;&#x914D;&#x7F6E;&#x6CE8;&#x89E3;" class="anchor-navigation-ex-anchor" href="#&#x5B9A;&#x4E49;&#x914D;&#x7F6E;&#x6CE8;&#x89E3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9A;&#x4E49;&#x914D;&#x7F6E;&#x6CE8;&#x89E3;</h3>
<pre><code class="lang-java">
<span class="hljs-meta">@Retention</span>(RetentionPolicy.RUNTIME)
<span class="hljs-meta">@Target</span>(ElementType.TYPE)
<span class="hljs-comment">// &#x5BFC;&#x5165;</span>
<span class="hljs-meta">@Import</span>(UserBeanConfigImportSelector.class)
<span class="hljs-keyword">public</span> <span class="hljs-meta">@interface</span> EnableUserBeanAutoConfig {

}
</code></pre>
<h3 id="&#x4E3B;&#x7C7B;"><a name="&#x4E3B;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x4E3B;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E3B;&#x7C7B;</h3>
<pre><code class="lang-java"><span class="hljs-meta">@EnableUserBeanAutoConfig</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImportTestMain</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        AnnotationConfigApplicationContext applicationContext = <span class="hljs-keyword">new</span> AnnotationConfigApplicationContext();
        applicationContext.register(ImportTestMain.class);
        applicationContext.refresh();

        UserBean bean = applicationContext.getBean(UserBean.class);

        <span class="hljs-comment">// {&quot;name&quot;:&quot;&#x5F20;&#x4E09;&quot;,&quot;userId&quot;:12000}</span>
        System.out.println(JSON.toJSONString(bean));

        applicationContext.close();
    }

}
</code></pre>
<p>&#x8BB2;&#x89E3;&#xFF1A;ImportTestMain&#x4E3B;&#x7C7B;&#x4E0A;&#x9762;&#x6709;&#x6DFB;&#x52A0;&#x6CE8;&#x89E3;@EnableUserBeanAutoConfig&#xFF0C;&#x8FD9;&#x4E2A;&#x6CE8;&#x89E3;&#x7C7B;&#x4F7F;&#x7528;&#x4E86;@Import(UserBeanConfigImportSelector.class)&#xFF0C;&#x5BFC;&#x5165;&#x4E86;UserBeanConfigImportSelector&#x9009;&#x62E9;&#x5668;&#xFF0C;UserBeanConfigImportSelector&#x7684;selectImports&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4E86;&#x914D;&#x7F6E;&#x7C7B;UserBeanAutoConfig&#xFF0C;&#x6B64;&#x7C7B;&#x53CA;&#x91CC;&#x9762;&#x7684;&#x6240;&#x6709;&#x7684;@Bean&#x4FEE;&#x9970;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x4F1A;&#x88AB;spring boot&#x6CE8;&#x5165;&#x5230;bean&#x5BB9;&#x5668;&#x4E2D;&#x5E76;&#x521D;&#x59CB;&#x5316;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;UserBean bean = applicationContext.getBean(UserBean.class); &#x5C31;&#x53EF;&#x4EE5;&#x4ECE;&#x5BB9;&#x5668;&#x4E2D;&#x83B7;&#x53D6;&#x5230;UserBean &#x8FD9;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;</p>
<h2 id="enableautoconfiguration"><a name="enableautoconfiguration" class="anchor-navigation-ex-anchor" href="#enableautoconfiguration"><i class="fa fa-link" aria-hidden="true"></i></a>@EnableAutoConfiguration</h2>
<p>Springboot&#x4E2D;&#x9ED8;&#x8BA4;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#x539F;&#x7406;&#xFF1A;</p>
<p>&#x542F;&#x52A8;&#x7C7B;&#x4E0A;</p>
<p>@SpringBootApplication  -&gt;  @EnableAutoConfiguration  -&gt;  @Import(AutoConfigurationImportSelector.class)</p>
<p>@Import &#x673A;&#x5236;&#x5C31;&#x662F;springboot&#x4F1A;&#x6267;&#x884C;<strong>selectImports</strong>&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x7684;&#x6240;&#x6709;&#x7C7B;&#xFF0C;&#x7136;&#x540E;&#x52A0;&#x8F7D;&#x5230;beanfactory&#x91CC;&#x9762;&#x5E76;&#x521D;&#x59CB;&#x5316;</p>
<h2 id="autoconfigurationimportselector"><a name="autoconfigurationimportselector" class="anchor-navigation-ex-anchor" href="#autoconfigurationimportselector"><i class="fa fa-link" aria-hidden="true"></i></a>AutoConfigurationImportSelector</h2>
<p>&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF1A;ImportSelector</p>
<p>org.springframework.context.annotation.ImportSelector</p>
<p>&#x65B9;&#x6CD5;&#xFF1A;<strong>selectImports</strong>(AnnotationMetadata)</p>
<pre><code class="lang-java">
<span class="hljs-meta">@Override</span>
<span class="hljs-keyword">public</span> String[] selectImports(AnnotationMetadata annotationMetadata) {

    <span class="hljs-keyword">if</span> (!isEnabled(annotationMetadata)) {
        <span class="hljs-keyword">return</span> NO_IMPORTS;
    }

    AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader
            .loadMetadata(<span class="hljs-keyword">this</span>.beanClassLoader);

    <span class="hljs-comment">// &#x4ECE; META-INF/spring.factories &#x91CC;&#x9762;&#x83B7;&#x53D6; EnableAutoConfiguration &#x914D;&#x7F6E;</span>
    AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(autoConfigurationMetadata, annotationMetadata);

    <span class="hljs-comment">// &#x8FD4;&#x56DE; &#x6240;&#x6709;&#x7684; &#x81EA;&#x52A8;&#x914D;&#x7F6E;&#x7C7B; &#x52A0;&#x8F7D;&#x5230;beanfactory&#x91CC;&#x9762; &#x521D;&#x59CB;&#x5316;</span>
    <span class="hljs-keyword">return</span> StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}
</code></pre>
<p>&#x65B9;&#x6CD5;&#xFF1A;<strong>getAutoConfigurationEntry</strong>(autoConfigurationMetadata, annotationMetadata)</p>
<pre><code class="lang-java">
<span class="hljs-function"><span class="hljs-keyword">protected</span> AutoConfigurationEntry <span class="hljs-title">getAutoConfigurationEntry</span><span class="hljs-params">(AutoConfigurationMetadata autoConfigurationMetadata,
        AnnotationMetadata annotationMetadata)</span> </span>{

    <span class="hljs-keyword">if</span> (!isEnabled(annotationMetadata)) {
        <span class="hljs-keyword">return</span> EMPTY_ENTRY;
    }
    AnnotationAttributes attributes = getAttributes(annotationMetadata);

    <span class="hljs-comment">// &#x4ECE; META-INF/spring.factories &#x91CC;&#x9762;&#x83B7;&#x53D6; EnableAutoConfiguration &#x914D;&#x7F6E;</span>
    List&lt;String&gt; configurations = getCandidateConfigurations(annotationMetadata, attributes);

    configurations = removeDuplicates(configurations);
    Set&lt;String&gt; exclusions = getExclusions(annotationMetadata, attributes);
    checkExcludedClasses(configurations, exclusions);
    configurations.removeAll(exclusions);
    configurations = filter(configurations, autoConfigurationMetadata);
    fireAutoConfigurationImportEvents(configurations, exclusions);
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> AutoConfigurationEntry(configurations, exclusions);
}
</code></pre>
<p>&#x65B9;&#x6CD5;&#xFF1A;<strong>getCandidateConfigurations</strong>(AnnotationMetadata metadata, AnnotationAttributes attributes)</p>
<pre><code class="lang-java">
<span class="hljs-function"><span class="hljs-keyword">protected</span> List&lt;String&gt; <span class="hljs-title">getCandidateConfigurations</span><span class="hljs-params">(AnnotationMetadata metadata, AnnotationAttributes attributes)</span> </span>{

    <span class="hljs-comment">// &#x8BFB;&#x53D6; EnableAutoConfiguration.class &#x5728; META-INF/spring.factories &#x4E0B;&#x914D;&#x7F6E;&#x7684;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#x7C7B;</span>
    List&lt;String&gt; configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(),
            getBeanClassLoader());

    Assert.notEmpty(configurations, <span class="hljs-string">&quot;No auto configuration classes found in META-INF/spring.factories. If you &quot;</span>
            + <span class="hljs-string">&quot;are using a custom packaging, make sure that file is correct.&quot;</span>);
    <span class="hljs-keyword">return</span> configurations;
}
</code></pre>
<p>// &#x8BFB;&#x53D6; EnableAutoConfiguration.class &#x5728; META-INF/spring.factories &#x4E0B;&#x914D;&#x7F6E;&#x7684;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#x7C7B;</p>
<p>SpringFactoriesLoader.loadFactoryNames(Class&lt;?&gt;, ClassLoader)</p>
<p>spring boot&#x5728; spring-boot-autoconfigure-x.x.x.RELEASE.jar &#x5305;&#x7684;  META-INF/spring.factories &#x4E0B;&#x9762;&#x914D;&#x7F6E;&#x7684;&#x5176;&#x4ED6;&#x7B2C;&#x4E09;&#x65B9;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#x7C7B;</p>
<pre><code class="lang-properties">
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
org.springframework.boot.autoconfigure.cloud.CloudServiceConnectorsAutoConfiguration,\
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\
org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveRestClientAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\
org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration,\
org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration,\
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\
org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\
org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\
org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\
org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\
org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\
org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\
org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\
org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,\
org.springframework.boot.autoconfigure.security.rsocket.RSocketSecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyAutoConfiguration,\
org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration
</code></pre>
<h2 id="import"><a name="import" class="anchor-navigation-ex-anchor" href="#import"><i class="fa fa-link" aria-hidden="true"></i></a>@Import</h2>
<p>&#x5177;&#x4F53;@Import&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#xFF1A;</p>
<p>&#x6E90;&#x7801;&#x5206;&#x6790;&#xFF1A;</p>
<p>&#x5148;&#x7F16;&#x5199;&#x4E00;&#x4E2A;&#x542F;&#x52A8;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-meta">@EnableApolloConfig</span>
<span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SpringBootLearnApplication</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        SpringApplication.run(SpringBootLearnApplication.class, args);
    }

}
</code></pre>
<p>&#x8FDB;&#x5165;&#x5230; SpringApplication.run(SpringBootLearnApplication.class, args);</p>
<p>&#x4E00;&#x76F4;&#x70B9;run&#x65B9;&#x6CD5;</p>
<p>org.springframework.boot.SpringApplication.run(String...)</p>
<pre><code class="lang-java">
<span class="hljs-function"><span class="hljs-keyword">public</span> ConfigurableApplicationContext <span class="hljs-title">run</span><span class="hljs-params">(String... args)</span> </span>{
    StopWatch stopWatch = <span class="hljs-keyword">new</span> StopWatch();
    stopWatch.start();
    ConfigurableApplicationContext context = <span class="hljs-keyword">null</span>;
    Collection&lt;SpringBootExceptionReporter&gt; exceptionReporters = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
    configureHeadlessProperty();
    SpringApplicationRunListeners listeners = getRunListeners(args);
    listeners.starting();
    <span class="hljs-keyword">try</span> {
        ApplicationArguments applicationArguments = <span class="hljs-keyword">new</span> DefaultApplicationArguments(args);
        ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
        configureIgnoreBeanInfo(environment);
        Banner printedBanner = printBanner(environment);
        context = createApplicationContext();
        exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,
                <span class="hljs-keyword">new</span> Class[] { ConfigurableApplicationContext.class }, context);
        prepareContext(context, environment, listeners, applicationArguments, printedBanner);

        <span class="hljs-comment">// &#x52A0;&#x8F7D; spring&#x5BB9;&#x5668; &#x4E0A;&#x4E0B;&#x6587;</span>
        refreshContext(context);

        afterRefresh(context, applicationArguments);
        stopWatch.stop();
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.logStartupInfo) {
            <span class="hljs-keyword">new</span> StartupInfoLogger(<span class="hljs-keyword">this</span>.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
        }
        listeners.started(context);
        callRunners(context, applicationArguments);
    }
    <span class="hljs-keyword">catch</span> (Throwable ex) {
        handleRunFailure(context, ex, exceptionReporters, listeners);
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> IllegalStateException(ex);
    }

    <span class="hljs-keyword">try</span> {
        listeners.running(context);
    }
    <span class="hljs-keyword">catch</span> (Throwable ex) {
        handleRunFailure(context, ex, exceptionReporters, <span class="hljs-keyword">null</span>);
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> IllegalStateException(ex);
    }
    <span class="hljs-keyword">return</span> context;
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A; refreshContext(context); </p>
<pre><code class="lang-java">
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">refreshContext</span><span class="hljs-params">(ConfigurableApplicationContext context)</span> </span>{
    <span class="hljs-comment">// &#x5237;&#x65B0;</span>
    refresh(context);

    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.registerShutdownHook) {
        <span class="hljs-keyword">try</span> {
            context.registerShutdownHook();
        }
        <span class="hljs-keyword">catch</span> (AccessControlException ex) {
            <span class="hljs-comment">// Not allowed in some environments.</span>
        }
    }
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;refresh(context);</p>
<p>&#x4E00;&#x76F4;&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A; refresh()</p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">refresh</span><span class="hljs-params">(ApplicationContext applicationContext)</span> </span>{
    Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext);
    ((AbstractApplicationContext) applicationContext).refresh();
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;</p>
<p>org.springframework.context.support.AbstractApplicationContext.refresh()</p>
<p>&#x6B64;&#x65B9;&#x6CD5;&#x4E2D; &#x5BF9;context&#x4E0A;&#x4E0B;&#x6587;&#x5BB9;&#x5668;&#x521D;&#x59CB;&#x5316;&#xFF0C;</p>
<pre><code class="lang-java">
<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">refresh</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> BeansException, IllegalStateException </span>{
    <span class="hljs-keyword">synchronized</span> (<span class="hljs-keyword">this</span>.startupShutdownMonitor) {
        <span class="hljs-comment">// Prepare this context for refreshing.</span>
        prepareRefresh();

        <span class="hljs-comment">// Tell the subclass to refresh the internal bean factory.</span>
        ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

        <span class="hljs-comment">// Prepare the bean factory for use in this context.</span>
        prepareBeanFactory(beanFactory);

        <span class="hljs-keyword">try</span> {
            <span class="hljs-comment">// Allows post-processing of the bean factory in context subclasses.</span>
            postProcessBeanFactory(beanFactory);

            <span class="hljs-comment">// Invoke factory processors registered as beans in the context.</span>
            invokeBeanFactoryPostProcessors(beanFactory);

            <span class="hljs-comment">// &#x6CE8;&#x518C; bean processors</span>
            <span class="hljs-comment">// Register bean processors that intercept bean creation.</span>
            registerBeanPostProcessors(beanFactory);

            <span class="hljs-comment">// Initialize message source for this context.</span>
            initMessageSource();

            <span class="hljs-comment">// Initialize event multicaster for this context.</span>
            initApplicationEventMulticaster();

            <span class="hljs-comment">// Initialize other special beans in specific context subclasses.</span>
            onRefresh();

            <span class="hljs-comment">// Check for listener beans and register them.</span>
            registerListeners();

            <span class="hljs-comment">// Instantiate all remaining (non-lazy-init) singletons.</span>
            finishBeanFactoryInitialization(beanFactory);

            <span class="hljs-comment">// Last step: publish corresponding event.</span>
            finishRefresh();
        }

        <span class="hljs-keyword">catch</span> (BeansException ex) {
            <span class="hljs-keyword">if</span> (logger.isWarnEnabled()) {
                logger.warn(<span class="hljs-string">&quot;Exception encountered during context initialization - &quot;</span> +
                        <span class="hljs-string">&quot;cancelling refresh attempt: &quot;</span> + ex);
            }

            <span class="hljs-comment">// Destroy already created singletons to avoid dangling resources.</span>
            destroyBeans();

            <span class="hljs-comment">// Reset &apos;active&apos; flag.</span>
            cancelRefresh(ex);

            <span class="hljs-comment">// Propagate exception to caller.</span>
            <span class="hljs-keyword">throw</span> ex;
        }

        <span class="hljs-keyword">finally</span> {
            <span class="hljs-comment">// Reset common introspection caches in Spring&apos;s core, since we</span>
            <span class="hljs-comment">// might not ever need metadata for singleton beans anymore...</span>
            resetCommonCaches();
        }
    }
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;invokeBeanFactoryPostProcessors(beanFactory);</p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">invokeBeanFactoryPostProcessors</span><span class="hljs-params">(ConfigurableListableBeanFactory beanFactory)</span> </span>{
    <span class="hljs-comment">// &#x8FDB;&#x5165;</span>
    PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors());

    <span class="hljs-comment">// Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime</span>
    <span class="hljs-comment">// (e.g. through an @Bean method registered by ConfigurationClassPostProcessor)</span>
    <span class="hljs-keyword">if</span> (beanFactory.getTempClassLoader() == <span class="hljs-keyword">null</span> &amp;&amp; beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
        beanFactory.addBeanPostProcessor(<span class="hljs-keyword">new</span> LoadTimeWeaverAwareProcessor(beanFactory));
        beanFactory.setTempClassLoader(<span class="hljs-keyword">new</span> ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader()));
    }
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x5230;&#xFF1A;PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory, List<beanfactorypostprocessor>)</beanfactorypostprocessor></p>
<p>&#x70B9;&#x51FB;&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);</p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">invokeBeanDefinitionRegistryPostProcessors</span><span class="hljs-params">(
        Collection&lt;? extends BeanDefinitionRegistryPostProcessor&gt; postProcessors, BeanDefinitionRegistry registry)</span> </span>{

    <span class="hljs-keyword">for</span> (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) {
        <span class="hljs-comment">// &#x89E3;&#x6790;</span>
        postProcessor.postProcessBeanDefinitionRegistry(registry);
    }
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;postProcessor.postProcessBeanDefinitionRegistry(registry);</p>
<p>ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(BeanDefinitionRegistry)</p>
<pre><code class="lang-java"><span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">postProcessBeanDefinitionRegistry</span><span class="hljs-params">(BeanDefinitionRegistry registry)</span> </span>{
    <span class="hljs-keyword">int</span> registryId = System.identityHashCode(registry);
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.registriesPostProcessed.contains(registryId)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> IllegalStateException(
                <span class="hljs-string">&quot;postProcessBeanDefinitionRegistry already called on this post-processor against &quot;</span> + registry);
    }
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.factoriesPostProcessed.contains(registryId)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> IllegalStateException(
                <span class="hljs-string">&quot;postProcessBeanFactory already called on this post-processor against &quot;</span> + registry);
    }
    <span class="hljs-keyword">this</span>.registriesPostProcessed.add(registryId);

    <span class="hljs-comment">// &#x8FDB;&#x5165;</span>
    processConfigBeanDefinitions(registry);
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;processConfigBeanDefinitions(registry);</p>
<pre><code class="lang-java">
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">processConfigBeanDefinitions</span><span class="hljs-params">(BeanDefinitionRegistry registry)</span> </span>{
    List&lt;BeanDefinitionHolder&gt; configCandidates = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
    String[] candidateNames = registry.getBeanDefinitionNames();

    <span class="hljs-keyword">for</span> (String beanName : candidateNames) {
        BeanDefinition beanDef = registry.getBeanDefinition(beanName);
        <span class="hljs-keyword">if</span> (beanDef.getAttribute(ConfigurationClassUtils.CONFIGURATION_CLASS_ATTRIBUTE) != <span class="hljs-keyword">null</span>) {
            <span class="hljs-keyword">if</span> (logger.isDebugEnabled()) {
                logger.debug(<span class="hljs-string">&quot;Bean definition has already been processed as a configuration class: &quot;</span> + beanDef);
            }
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, <span class="hljs-keyword">this</span>.metadataReaderFactory)) {
            configCandidates.add(<span class="hljs-keyword">new</span> BeanDefinitionHolder(beanDef, beanName));
        }
    }

    <span class="hljs-comment">// Return immediately if no @Configuration classes were found</span>
    <span class="hljs-keyword">if</span> (configCandidates.isEmpty()) {
        <span class="hljs-keyword">return</span>;
    }

    <span class="hljs-comment">// Sort by previously determined @Order value, if applicable</span>
    configCandidates.sort((bd1, bd2) -&gt; {
        <span class="hljs-keyword">int</span> i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition());
        <span class="hljs-keyword">int</span> i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition());
        <span class="hljs-keyword">return</span> Integer.compare(i1, i2);
    });

    <span class="hljs-comment">// Detect any custom bean name generation strategy supplied through the enclosing application context</span>
    SingletonBeanRegistry sbr = <span class="hljs-keyword">null</span>;
    <span class="hljs-keyword">if</span> (registry <span class="hljs-keyword">instanceof</span> SingletonBeanRegistry) {
        sbr = (SingletonBeanRegistry) registry;
        <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.localBeanNameGeneratorSet) {
            BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton(
                    AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
            <span class="hljs-keyword">if</span> (generator != <span class="hljs-keyword">null</span>) {
                <span class="hljs-keyword">this</span>.componentScanBeanNameGenerator = generator;
                <span class="hljs-keyword">this</span>.importBeanNameGenerator = generator;
            }
        }
    }

    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.environment == <span class="hljs-keyword">null</span>) {
        <span class="hljs-keyword">this</span>.environment = <span class="hljs-keyword">new</span> StandardEnvironment();
    }

    <span class="hljs-comment">// &#x89E3;&#x6790; &#x6BCF;&#x4E00;&#x4E2A; @Configuration &#x7C7B;</span>
    <span class="hljs-comment">// Parse each @Configuration class</span>
    ConfigurationClassParser parser = <span class="hljs-keyword">new</span> ConfigurationClassParser(
            <span class="hljs-keyword">this</span>.metadataReaderFactory, <span class="hljs-keyword">this</span>.problemReporter, <span class="hljs-keyword">this</span>.environment,
            <span class="hljs-keyword">this</span>.resourceLoader, <span class="hljs-keyword">this</span>.componentScanBeanNameGenerator, registry);

    Set&lt;BeanDefinitionHolder&gt; candidates = <span class="hljs-keyword">new</span> LinkedHashSet&lt;&gt;(configCandidates);
    Set&lt;ConfigurationClass&gt; alreadyParsed = <span class="hljs-keyword">new</span> HashSet&lt;&gt;(configCandidates.size());
    do {

        <span class="hljs-comment">// &#x8FDB;&#x5165;&#x65B9;&#x6CD5;</span>
        parser.parse(candidates);
        parser.validate();

        Set&lt;ConfigurationClass&gt; configClasses = <span class="hljs-keyword">new</span> LinkedHashSet&lt;&gt;(parser.getConfigurationClasses());
        configClasses.removeAll(alreadyParsed);

        <span class="hljs-comment">// Read the model and create bean definitions based on its content</span>
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.reader == <span class="hljs-keyword">null</span>) {
            <span class="hljs-keyword">this</span>.reader = <span class="hljs-keyword">new</span> ConfigurationClassBeanDefinitionReader(
                    registry, <span class="hljs-keyword">this</span>.sourceExtractor, <span class="hljs-keyword">this</span>.resourceLoader, <span class="hljs-keyword">this</span>.environment,
                    <span class="hljs-keyword">this</span>.importBeanNameGenerator, parser.getImportRegistry());
        }
        <span class="hljs-keyword">this</span>.reader.loadBeanDefinitions(configClasses);
        alreadyParsed.addAll(configClasses);

        candidates.clear();
        <span class="hljs-keyword">if</span> (registry.getBeanDefinitionCount() &gt; candidateNames.length) {
            String[] newCandidateNames = registry.getBeanDefinitionNames();
            Set&lt;String&gt; oldCandidateNames = <span class="hljs-keyword">new</span> HashSet&lt;&gt;(Arrays.asList(candidateNames));
            Set&lt;String&gt; alreadyParsedClasses = <span class="hljs-keyword">new</span> HashSet&lt;&gt;();
            <span class="hljs-keyword">for</span> (ConfigurationClass configurationClass : alreadyParsed) {
                alreadyParsedClasses.add(configurationClass.getMetadata().getClassName());
            }
            <span class="hljs-keyword">for</span> (String candidateName : newCandidateNames) {
                <span class="hljs-keyword">if</span> (!oldCandidateNames.contains(candidateName)) {
                    BeanDefinition bd = registry.getBeanDefinition(candidateName);
                    <span class="hljs-keyword">if</span> (ConfigurationClassUtils.checkConfigurationClassCandidate(bd, <span class="hljs-keyword">this</span>.metadataReaderFactory) &amp;&amp;
                            !alreadyParsedClasses.contains(bd.getBeanClassName())) {
                        candidates.add(<span class="hljs-keyword">new</span> BeanDefinitionHolder(bd, candidateName));
                    }
                }
            }
            candidateNames = newCandidateNames;
        }
    }
    <span class="hljs-keyword">while</span> (!candidates.isEmpty());

    <span class="hljs-comment">// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes</span>
    <span class="hljs-keyword">if</span> (sbr != <span class="hljs-keyword">null</span> &amp;&amp; !sbr.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
        sbr.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
    }

    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.metadataReaderFactory <span class="hljs-keyword">instanceof</span> CachingMetadataReaderFactory) {
        <span class="hljs-comment">// Clear cache in externally provided MetadataReaderFactory; this is a no-op</span>
        <span class="hljs-comment">// for a shared cache since it&apos;ll be cleared by the ApplicationContext.</span>
        ((CachingMetadataReaderFactory) <span class="hljs-keyword">this</span>.metadataReaderFactory).clearCache();
    }
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;parser.parse(candidates);</p>
<pre><code class="lang-java">
<span class="hljs-comment">// Parse each @Configuration class</span>
ConfigurationClassParser parser = <span class="hljs-keyword">new</span> ConfigurationClassParser(
        <span class="hljs-keyword">this</span>.metadataReaderFactory, <span class="hljs-keyword">this</span>.problemReporter, <span class="hljs-keyword">this</span>.environment,
        <span class="hljs-keyword">this</span>.resourceLoader, <span class="hljs-keyword">this</span>.componentScanBeanNameGenerator, registry);

parser.parse(candidates);
</code></pre>
<p>&#x4E00;&#x76F4;&#x8FDB;&#x5165;&#xFF1A;parse &#x65B9;&#x6CD5;</p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">void</span> <span class="hljs-title">parse</span><span class="hljs-params">(@Nullable String className, String beanName)</span> <span class="hljs-keyword">throws</span> IOException </span>{
    Assert.notNull(className, <span class="hljs-string">&quot;No bean class name for configuration class bean definition&quot;</span>);
    MetadataReader reader = <span class="hljs-keyword">this</span>.metadataReaderFactory.getMetadataReader(className);
    <span class="hljs-comment">// &#x89E3;&#x6790; @Configuration &#x7C7B;</span>
    processConfigurationClass(<span class="hljs-keyword">new</span> ConfigurationClass(reader, beanName));
}
</code></pre>
<p>&#x8FDB;&#x5165;&#x65B9;&#x6CD5;&#xFF1A;processConfigurationClass(new ConfigurationClass(reader, beanName));</p>
<p>&#x7136;&#x540E;&#x8FDB;&#x5165;&#xFF1A;sourceClass = doProcessConfigurationClass(configClass, sourceClass);</p>
<p>&#x6700;&#x540E;&#x8FDB;&#x5165;&#xFF1A;processImports(configClass, sourceClass, getImports(sourceClass), true);</p>
<p>&#x81F3;&#x6B64;&#xFF0C;&#x8BFB;&#x53D6;@Import &#x6CE8;&#x89E3;&#x7C7B;&#x83B7;&#x53D6;&#x5B9E;&#x73B0;ImportSelector&#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x8C03;&#x7528;selectImports&#x65B9;&#x6CD5;&#xFF0C;&#x83B7;&#x53D6;&#x5230;&#x914D;&#x7F6E;&#x7C7B;</p>
<p>String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata());</p>
<p>&#x52A0;&#x8F7D;&#x914D;&#x7F6E;&#x7C7B;&#xFF0C;</p>
<p>&#x89E3;&#x6790;@ImportResource&#x6CE8;&#x91CA;</p>
<p>&#x89E3;&#x6790;@Bean &#x6CE8;&#x91CA;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x52A0;&#x8F7D;&#x7B49;&#x64CD;&#x4F5C;</p>
<pre><code class="lang-java"><span class="hljs-comment">// Process individual @Bean methods</span>
<span class="hljs-comment">// &#x89E3;&#x6790; @Bean&#x6CE8;&#x91CA;&#x7684;&#x65B9;&#x6CD5;</span>
Set&lt;MethodMetadata&gt; beanMethods = retrieveBeanMethodMetadata(sourceClass);
<span class="hljs-keyword">for</span> (MethodMetadata methodMetadata : beanMethods) {
    configClass.addBeanMethod(<span class="hljs-keyword">new</span> BeanMethod(methodMetadata, configClass));
}
</code></pre>
<p>&#x89E3;&#x6790;&#x5B8C;&#x6210;</p>
<footer class="page-footer"><span class="copyright">Copyright @copy tianwyam 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-06-17 19:35:00
</span></footer>
                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="spring/spring_interview_questions_68.html" class="navigation navigation-prev " aria-label="Previous page: Spring面试题68">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="spring_feign.html" class="navigation navigation-next " aria-label="Next page: Feign在spring、springboot下使用">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"SpringBoot自动装载机制 - 源码分析","level":"11.1","depth":1,"next":{"title":"Feign在spring、springboot下使用","level":"12.1","depth":1,"path":"Spring/spring_feign.md","ref":"Spring/spring_feign.md","articles":[]},"previous":{"title":"Spring面试题68","level":"10.1","depth":1,"path":"Spring/spring/spring_interview_questions_68.md","ref":"Spring/spring/spring_interview_questions_68.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","github","tbfed-pagefooter","splitter","pageview-count","anchor-navigation-ex","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright @copy tianwyam 2021","modify_label":"最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"github":{"url":"https://github.com/tianwyam"},"livereload":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"pageview-count":{},"expandable-chapters-small":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tianwyam","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JAVA学习积累","links":{"sidebar":{"博客Blog":"https://blog.csdn.net/mybook201314"}},"gitbook":"*","description":"积累Java学习过程中的知识点，俗话说：好记性不如烂笔头"},"file":{"path":"Spring/springboot_auto_config.md","mtime":"2021-06-17T11:35:00.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-03T12:24:01.188Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

